package com.tuling.jucdemo.threadbase;

/**
 *  等join()执行完后以后，程序再继续执行，一般用于异步线程执行完以后才能继续执行的场景
 */
public class ThreadJoinDemo {
    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("t1 begin");
                try {
                    Thread.sleep(5000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("t1 end");
            }
        });
        long start = System.currentTimeMillis();
        t1.start();
        //主线程等待线程t执行完成
        t1.join();
        System.out.println("执行时间:"+(System.currentTimeMillis()-start));
        System.out.println("main Thread");
    }
}
